package experiment1;

import java.io.*;
import java.util.Scanner;

/**
 * @author 冯永龙
 * @date 2021/3/9 15:16
 */
public class task1 {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入文件路径: ");
        String file = sc.nextLine();
        int count = 0;
        BufferedReader buffered = new BufferedReader(new FileReader(file));
        String[] words = buffered.readLine().split("[ \t\\(\\)]");   //拆分字符串为数组

        String KEYWORDS[] = {"abstract", "assert", "boolen", "break", "byte", "case", "catch", "char", "class", "const",
                "continue", "default", "do", "double", "else", "enum", "extends", "final", "finally", "float", "for",
                "if", "implements", "import", "instanceof", "int", "interface", "long", "native", "new", "package",
                "private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch", "synchrpnized",
                "this", "throw", "throws", "transient", "try", "void", "volatile", "while"};

        for (String word : words) {
            for (String keyword : KEYWORDS) {
                if (word.equals(keyword)){
                    count++;
                    System.out.println(word);
                }
            }
        }

        System.out.println("该文件中关键词的个数为："+count);
    }
}
